/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.angholt.bookproject.wsdl;

import edu.chl.angholt.bookproject.db.Database;
import edu.chl.angholt.bookproject.db.entity.Author;
import edu.chl.angholt.bookproject.db.entity.Book;
import javax.jws.WebService;


/**
 * implementation for Web Service of the interface View1
 * @author Patric Peterson
 */
@WebService(endpointInterface = "edu.chl.angholt.bookproject.wsdl.View1")
public class View1Impl implements View1 {

    /**
     * retrieve a book by id from DB
     * @param id The id of the book.
     * @return  The book in question or null if nothing.
     */
    @Override
    public Book getBookById( Long id) {
        try{
        Book b = Database.getBookController().findEntity(id);
        return b;
        }catch(Exception e){
            System.err.println(e.getMessage());        
        }
        return null;
    }
    /**
     * retrieve a author by id from DB
     * @param id The id of the author.
     * @return  The author in question or null if nothing.
     */
    @Override
    public Author getAuthorById(Long id) {
        try{
        Author a = Database.getAuthorController().findEntity(id);
            return a;
        }catch(Exception e){
            System.err.println(e.getMessage());        
        }
        return null;

    }

    /**
     * retrieve a author by name from DB
     * @param name The name of the author.
     * @return  The author in question or null if nothing.
     */
    @Override
    public Author getAuthorByName( String name) {
        try{
            Author a = Database.getAuthorController().findAuthor(name);
            return a;
        }catch(Exception e){
            System.err.println(e.getMessage());        
        }
        return null;
    }
    /**
     * retrieve a book by title from DB
     * @param title The title of the author.
     * @return  The book in question or null if nothing.
     */    
@Override
    public Book getBookByTitle(String title) {
        try{
            Book b = Database.getBookController().findBook(title);      
            return b;
        }catch(Exception e){
            System.err.println(e.getMessage());        
        }
        return null;
    }
            
}
